Allow From to be specified on email agents

Andrew Cantino 8 lat temu
rodzic
commit
9afe6b3798

+ 1 - 1
Gemfile

@@ -184,5 +184,5 @@ if_true(ENV['DATABASE_ADAPTER'].strip == 'postgresql') do
184 184
 end
185 185
 
186 186
 if_true(ENV['DATABASE_ADAPTER'].strip == 'mysql2') do
187
-  gem 'mysql2', '~> 0.3.16'
187
+  gem 'mysql2', '~> 0.3.20'
188 188
 end

+ 2 - 2
Gemfile.lock

@@ -322,7 +322,7 @@ GEM
322 322
     multi_json (1.11.2)
323 323
     multi_xml (0.5.5)
324 324
     multipart-post (2.0.0)
325
-    mysql2 (0.3.16)
325
+    mysql2 (0.3.20)
326 326
     naught (1.0.0)
327 327
     nenv (0.2.0)
328 328
     net-ftp-list (3.2.8)
@@ -624,7 +624,7 @@ DEPENDENCIES
624 624
   mini_magick
625 625
   mqtt
626 626
   multi_xml
627
-  mysql2 (~> 0.3.16)
627
+  mysql2 (~> 0.3.20)
628 628
   net-ftp-list (~> 3.2.8)
629 629
   nokogiri (= 1.6.7.2)
630 630
   omniauth

+ 4 - 1
app/mailers/system_mailer.rb

@@ -5,6 +5,9 @@ class SystemMailer < ActionMailer::Base
5 5
     @groups = options[:groups]
6 6
     @headline = options[:headline]
7 7
     @body = options[:body]
8
-    mail :to => options[:to], :subject => options[:subject]
8
+
9
+    mail_options = { to: options[:to], subject: options[:subject] }
10
+    mail_options[:from] = options[:from] if options[:from].present?
11
+    mail(mail_options)
9 12
   end
10 13
 end

+ 11 - 2
app/models/agents/email_agent.rb

@@ -21,6 +21,8 @@ module Agents
21 21
       You can specify one or more `recipients` for the email, or skip the option in order to send the email to your
22 22
       account's default email address.
23 23
 
24
+      You can provide a `from` address for the email, or leave it blank to default to the value of `EMAIL_FROM_ADDRESS` (`#{ENV['EMAIL_FROM_ADDRESS']}`).
25
+
24 26
       Set `expected_receive_period_in_days` to the maximum amount of time that you'd expect to pass between Events being received by this Agent.
25 27
     MD
26 28
 
@@ -35,8 +37,15 @@ module Agents
35 37
     def receive(incoming_events)
36 38
       incoming_events.each do |event|
37 39
         recipients(event.payload).each do |recipient|
38
-          log "Sending digest mail to #{recipient} with event #{event.id}"
39
-          SystemMailer.send_message(:to => recipient, :subject => interpolated(event)['subject'], :headline => interpolated(event)['headline'], :body => interpolated(event)['body'], :groups => [present(event.payload)]).deliver_later
40
+          log "Sending mail to #{recipient} with event #{event.id}"
41
+          SystemMailer.send_message(
42
+            to: recipient,
43
+            from: interpolated(event)['from'],
44
+            subject: interpolated(event)['subject'],
45
+            headline: interpolated(event)['headline'],
46
+            body: interpolated(event)['body'],
47
+            groups: [present(event.payload)]
48
+          ).deliver_later
40 49
         end
41 50
       end
42 51
     end

+ 9 - 1
app/models/agents/email_digest_agent.rb

@@ -16,6 +16,8 @@ module Agents
16 16
       You can specify one or more `recipients` for the email, or skip the option in order to send the email to your
17 17
       account's default email address.
18 18
 
19
+      You can provide a `from` address for the email, or leave it blank to default to the value of `EMAIL_FROM_ADDRESS` (`#{ENV['EMAIL_FROM_ADDRESS']}`).
20
+
19 21
       Set `expected_receive_period_in_days` to the maximum amount of time that you'd expect to pass between Events being received by this Agent.
20 22
     MD
21 23
 
@@ -42,7 +44,13 @@ module Agents
42 44
         groups = self.memory['queue'].map { |payload| present(payload) }
43 45
         recipients.each do |recipient|
44 46
           log "Sending digest mail to #{recipient} with events [#{ids}]"
45
-          SystemMailer.send_message(:to => recipient, :subject => interpolated['subject'], :headline => interpolated['headline'], :groups => groups).deliver_later
47
+          SystemMailer.send_message(
48
+            to: recipient,
49
+            from: interpolated['from'],
50
+            subject: interpolated['subject'],
51
+            headline: interpolated['headline'],
52
+            groups: groups
53
+          ).deliver_later
46 54
         end
47 55
         self.memory['queue'] = []
48 56
         self.memory['events'] = []